#include"Queue.h"

BTNode* BuyNode(BTDataType x)
{
    BTNode *newnode=(BTNode*)malloc(sizeof(BTNode));
    newnode->val=x;
    newnode->right=NULL;
    newnode->left=NULL;
    return  newnode;
}


BTNode* CreatBinaryTree()//链接节点
{
    BTNode*node1= BuyNode(1);
    BTNode*node2=BuyNode(2);
    BTNode*node3=BuyNode(3);
    BTNode* node4 = BuyNode(4);
    BTNode* node5 = BuyNode(5);
    BTNode* node6 = BuyNode(6);
    node1->left = node2;
    node1->right = node3;
    node2->left = node4;
    node2->right=node5;
    node3->left=node6;
    return node1;
}
void SequenceTree(BTNode*root)//中序遍历
{
    po tail;
    QueueNoteInit(&tail);//初始化

    QueueNotePush(&tail,root);//插入头部数据


    while(!QueueEmpty(&tail))
    {
        BTNode*Front=QueueFront(&tail);//获取头部的节点
        printf("%d ",Front->val);//打印出队列的数据
        QueuePop(&tail);

        if(Front->left!=NULL)//队头出队列入左节点
        {
            QueueNotePush(&tail,Front->left);
        }
        if(Front->left!=NULL)//队头出队列入他的右节点
        {
            QueueNotePush(&tail,Front->right);
        }



    }
    QueueDestroy(&tail);//释放

}
int BinaryTreeComplete(BTNode* root)
{
    po tail;
    QueueNoteInit(&tail);//初始化

    QueueNotePush(&tail,root);//插入头部数据


    while(!QueueEmpty(&tail))//把全部入队列
    {
        BTNode*Front=QueueFront(&tail);//获取头部的节点
        QueuePop(&tail);
        if(Front==NULL)
        {
            break;
        }
            QueueNotePush(&tail,Front->left);
            QueueNotePush(&tail,Front->right);
    }
    while(!QueueEmpty(&tail))//看后面的NULL是不是连续的
    {
        BTNode*Front=QueueFront(&tail);
        if(Front!=NULL)
        {
            return false;
        }
        QueuePop(&tail);

    }
    QueueDestroy(&tail);//释放
    return true;
}
int main()
{
    BTNode*ret= CreatBinaryTree();
    //SequenceTree(ret);

    if(BinaryTreeComplete(ret))
    {
        printf("1");
    }
}
